import { fileURLToPath, URL } from "node:url";

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueDevTools from "vite-plugin-vue-devtools";
import chalk from "chalk";
import generateExports from "./generate-exports";

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    {
      name: "pure-admin-welcome",
      configureServer() {
        console.log(chalk.cyan(`佛祖保佑，永无 bug`));
      },
      buildStart() {
        generateExports();
      },
    },
    vueDevTools(),
  ],
  // css: {
  //   preprocessorOptions: {
  //     scss: { api: "modern-compiler" },
  //   },
  // },
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)), // ESM
      // "@typings": path.resolve(__dirname, "types/index.ts"), // CommonJS
      "@typings": fileURLToPath(new URL("./types/index.ts", import.meta.url)),
    },
  },
  server: {
    port: 5174,
    strictPort: true, // 如果端口被占用，直接报错
  },
});
